package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.dto.kaoshi2DTO;
import com.maxatime.pojo.entity.kaoshi2;
import com.maxatime.service.Ssbkaoshi3;
import com.maxatime.util.MyContent;

//11月份考试题
@Controller
@RequestMapping("/Ssbkaoshi3")
public class Ssbconteroller3 {
	@Autowired
	Ssbkaoshi3 ssbkaoshi3;

	@RequestMapping("/cha")
	public String cha() {
		return "Ssbks3/kaoshi";
	}

	//查询
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody kaoshi2 kaoshi2) {
//		JSONObject jsonObj = JSONObject.parseObject(strReq);
//		int pageNum = jsonObj.getInteger(BusinessContents.PAGE_NUM);
//		int pageSize = jsonObj.getInteger(BusinessContents.PAGE_SIZE);
		Map<String, Object> m = new HashMap<>();
	//	kaoshi2DTO kaoshi2dto = new kaoshi2DTO();
//		kaoshi2dto.setPageNum(pageNum);
//		kaoshi2dto.setPageSize(pageSize);
		Map<String, Object> list = ssbkaoshi3.listdate(kaoshi2);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, list.get("list"));
		m.put("pageInfo", list.get("pageInfo"));
		return m;

	}

	// 新增
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody kaoshi2 kaoshi2) {
		Map<String, Object> m = new HashMap<>();
		ssbkaoshi3.insertSelective(kaoshi2);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}

	// 删除
	@RequestMapping("/del")
	@ResponseBody
	public Map<String, Object> del(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkid = jsonObj.getInteger("pkid");
		ssbkaoshi3.deleteByPrimaryKey(pkid);
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, "2222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}

	// 反显
	@RequestMapping("/findpkid")
	@ResponseBody
	public Map<String, Object> findpkid(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int pkid = jsonObj.getInteger("pkid");
		kaoshi2 kaoshi2 = ssbkaoshi3.findpkid(pkid);
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, kaoshi2);
		return m;
	}

	// 修改
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody kaoshi2 kaoshi2) {
		ssbkaoshi3.updateByPrimaryKeySelective(kaoshi2);
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
		return m;
	}

	// 饼状图
	@RequestMapping("/bzt")
	@ResponseBody
	public Map<String, Object> bzt(@RequestBody kaoshi2 kaoshi2) {
		Map<String, Object> m = new HashMap<>();
		List<kaoshi2> list = ssbkaoshi3.list(kaoshi2);
		m.put(MyContent.CODE, "0000");
		m.put(MyContent.MSG, "查询成功");
		m.put(MyContent.DATA, list);
		return m;
	}
}
